package cn.edu.jlu.community.app.services.express;

import android.os.Handler;
import android.os.Message;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import cn.edu.jlu.community.app.GlobalContext;
import cn.edu.jlu.community.util.Log;

/**
 * Created by lkk on 3/29/15.
 */
public class ConnHelper {
    private static final String EXPRESS_API_HOST = "http://m.kuaidi100.com/query";

    public static void Search(final String comId, final String expressNo, final Handler handler) {

        String url = EXPRESS_API_HOST + "?id=1" + "&type=" + comId + "&postid=" + expressNo;

        StringRequest stringRequest = new StringRequest(url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Message msg = new Message();
                        msg.what = 0;
                        msg.obj = response;
                        handler.sendMessage(msg);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        handler.sendEmptyMessage(-1);
                        Log.e(error.getMessage(), error);
                    }
                });

        GlobalContext.getRequestQueue().add(stringRequest);
    }
}